package com.example.common.mvi

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.databinding.ViewDataBinding
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import com.example.common.base.BaseFragment
import kotlinx.coroutines.launch

abstract class BaseMviFragment<T:ViewDataBinding>:BaseFragment<T>(){
    companion object{
        
    }
    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        var onCreateView = super.onCreateView(inflater, container, savedInstanceState)
        initData()
        updateUi()
        return onCreateView
    }

    private fun initData(){
        lifecycleScope.launch {
            sendViewIntent()
        }
    }
    private fun updateUi(){
        lifecycleScope.launch {
            lifecycle.repeatOnLifecycle(Lifecycle.State.STARTED){
                collectUiState()
            }
        }
    }
    open suspend fun sendViewIntent(){

    }
    open suspend fun collectUiState(){

    }
}